package com.xiaoshangkou.hellopra.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshangkou.hellopra.mapper.CategoryMapper;
import com.xiaoshangkou.hellopra.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    //分页查询类型
    public Page<Category> findPage(int page,int size){
        Page<Category> categoryPage = categoryMapper.selectPage(new Page<>(page, size), null);
        return categoryPage;
    }

    //添加版块
    public void add(Category category){
        categoryMapper.insert(category);
    }

    //根据id删除版块
    public void delete(Integer cid){
        categoryMapper.deleteById(cid);
    }

    //根据cid获取版块内容
    public Category findById(Integer cid){
        return categoryMapper.selectById(cid);
    }

    //查询所有版块
    public List<Category> findAll(){
        return categoryMapper.selectList(null);
    }

}
